package com.avic.rong.goodsSort.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.avic.rong.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Chenjiaxin on 2019/7/15 15:44
 * E-Mail Address：16601203965@163.com
 */
public class GoodsBzRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

//    private List<GoodsBzBean> list;
    private Context context;
    private LayoutInflater inflater;
    private View view;
    private GoodsBzTabRvAdapter adapter;
    private static int GuoNei = 0;
    private static int GuoNeiRv = 1;
    private List<String> itemList;

    public GoodsBzRvAdapter( Context context) {
//        this.list = list;
        this.context = context;
        this.inflater = LayoutInflater.from(context);
//        adapter = new GoodsBzTabRvAdapter(context);
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return GuoNei;
        } else if (position == 1) {
            return GuoNeiRv;
        } else {
            return super.getItemViewType(position);
        }
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        if (i == 0) {
            view = inflater.inflate(R.layout.view_goods_biaozhun_title, viewGroup, false);
            return new GoodsBzTitleViewHolder(view);
        } else {
            view = inflater.inflate(R.layout.view_goods_biaozhun_rv, viewGroup, false);
            return new GoodsBzTabRvViewHolder(view);
        }
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        if (viewHolder instanceof GoodsBzTitleViewHolder) {
            GoodsBzTitleViewHolder holder = (GoodsBzTitleViewHolder) viewHolder;
            List<String> titleList = new ArrayList<>();
//            for (int j =0; j<list.size(); j++){
//                titleList.add(list.get(j).getTitle());
//            }
            holder.tv.setText(titleList.get(i));
//            holder.img.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    if (adapter != null){
//                        if (adapter.getItemCount() == 4){
//                            adapter.addItemNums(itemList.size());
//                            adapter.notifyDataSetChanged();
//                        }else {
//                            adapter.addItemNums(4);
//                            adapter.notifyDataSetChanged();
//                        }
//                    }
//                    Toast.makeText(context, "点击了", Toast.LENGTH_SHORT).show();
//                }
//            });
        } else {
            GoodsBzTabRvViewHolder holder = (GoodsBzTabRvViewHolder) viewHolder;
            GridLayoutManager manager = new GridLayoutManager(context, 2);
            manager.setOrientation(GridLayoutManager.VERTICAL);
            holder.rv.setLayoutManager(manager);
//            adapter = new GoodsBzTabRvAdapter(context);
            holder.rv.setAdapter(adapter);
//            itemList = list.get(i).getList();
//            adapter.setList(itemList);
        }
    }

    @Override
    public int getItemCount() {
        return 0;
    }

    //    class GoodsBzRvViewHolder extends RecyclerView.ViewHolder{
//        TextView tv;
//        ImageView img;
//        public GoodsBzRvViewHolder(@NonNull View itemView) {
//            super(itemView);
//            tv = itemView.findViewById(R.id.goods_Bz_Tv);
//            img = itemView.findViewById(R.id.goods_Bz_Img);
//        }
//    }
    class GoodsBzTabRvViewHolder extends RecyclerView.ViewHolder {
        RecyclerView rv;

        public GoodsBzTabRvViewHolder(@NonNull View itemView) {
            super(itemView);
            rv = itemView.findViewById(R.id.goods_Bz_Rv1);
        }
    }

    class GoodsBzTitleViewHolder extends RecyclerView.ViewHolder {
        TextView tv;
        ImageView img;

        public GoodsBzTitleViewHolder(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.goods_Bz_Tv);
            img = itemView.findViewById(R.id.goods_Bz_SelectorImg);
        }
    }
}
